package com.igroupes.ovineherd.entity;

import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * 数据模型表字段实体
 * @author iuv
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)
@TableName(value = "data_model_attribute",autoResultMap = true)
public class DataModelAttributeEntity extends BaseEntity{
    public static final Integer ADD = 2;
    public static final Integer EDIT = 3;
    @TableId(type = IdType.AUTO)
    private Long id;
    private String beanType;
    
    /**
     * 对应表序列
     */
    private Long tableId;
    /**
     * 字段名
     */
    private String name;
    /**
     * 字段说明
     */
    private String desc;
    /**
     * 对应数据库名称
     */
    private String dbName;
    /**
     * 是否为空
     */
    private Integer isNull;

    /**
     * 对应数据创建的字段的个数
     */
    private Integer dbNumber = 1;

    private Integer order = 1;

    private Integer status; // 1:原始， 2:新增 4:原始的字段编辑（1+3） 5:新增的字段编辑(新增2+3)
    private Long versionId;
    private Long sourceId;

    /**
     * 剩余数据存储值
     */
    @TableField(typeHandler = JacksonTypeHandler.class)
    private JSONObject json;
    public DataModelAttributeEntity(Long tableId, String name, String dbName) {
        this.tableId = tableId;
        this.name = name;
        this.dbName = dbName;
        this.isNull = 1;
    }
    public DataModelAttributeEntity(Long tableId, String name, String dbName, Long versionId) {
        this.tableId = tableId;
        this.name = name;
        this.versionId = versionId;
        this.dbName = dbName;
        this.isNull = 1;
    }
    public DataModelAttributeEntity(String name, String dbName) {
        this.name = name;
        this.dbName = dbName;
        this.isNull = 1;
    }
    public DataModelAttributeEntity(String name,String desc, String dbName, Integer isNull) {
        this.name = name;
        this.desc = desc;
        this.dbName = dbName;
        this.isNull = isNull;
    }
    public DataModelAttributeEntity(String name,String desc, String dbName, Integer isNull, JSONObject json,
                                    String beanType, Integer order ) {
        this.name = name;
        this.desc = desc;
        this.dbName = dbName;
        this.isNull = isNull;
        this.json = json;
        this.beanType = beanType;
        this.order = order;
    }

    public DataModelAttributeEntity() {

    }
}
